<?php
namespace app\index\controller;
use app\index\model\Admin as AdminModel;
use app\index\model\AdminLog as AdminLogModel;

class Login extends Common
{
    public function index()
    {
        return $this->fetch();
    }

    public function logout()
    {
        session(null);
        $this->redirect('/login');
    }

    public function do_login()
    {
        $username = input('post.username');
        $password = input('post.password');
        $password = init_Password($password);
        $db_data = AdminModel::get([
            'nickname' => $username,
            'password' => $password,
            'status' => 1
        ]);
        if (isset($db_data['nickname'])) {
            $return_data = array(
                'nickname' => $db_data['nickname'],
            );
            session('Auth.Uid', $db_data['id']);
            session('Auth.Nickname', $db_data['nickname']);
            return setMsg(1, 'OK', $return_data);
        }
        return setMsg(0, 'Username or password error');
    }

    public function test()
    {
        dump(billno());
    }
}